﻿Public Class FrmCauHinhCSDL

    Private Sub FrmDBConfig_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        CreateConfigTable()
        CbxXacThuc.SelectedIndex = 0
    End Sub

    Private Sub BtnXacNhan_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnXacNhan.Click
        Dim r As DataRow
        r = config.NewRow()
        r("TenMayChu") = TxtMayChu.Text
        r("TenCSDL") = TxtCSDL.Text
        r("XacThuc") = CbxXacThuc.SelectedIndex
        r("TenNguoiDung") = TxtNguoiDung.Text
        r("MatKhau") = base64Encode(TxtMatKhau.Text)
        config.Rows.Clear()
        config.Rows.Add(r)
        config.WriteXml(configFile & ".xml")
        If CbxXacThuc.SelectedIndex = 0 Then
            db.Connect(TxtMayChu.Text, TxtCSDL.Text)
        Else
            db.Connect(TxtMayChu.Text, TxtCSDL.Text, TxtNguoiDung.Text, TxtMatKhau.Text)
        End If
        Close()
    End Sub

    Private Sub BtnHuyBo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnHuyBo.Click
        Close()
    End Sub

    Private Sub CbxXacThuc_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CbxXacThuc.SelectedIndexChanged
        If (CbxXacThuc.SelectedIndex = 0) Then
            Label4.Enabled = False
            Label5.Enabled = False
            TxtNguoiDung.Enabled = False
            TxtMatKhau.Enabled = False
        Else
            Label4.Enabled = True
            Label5.Enabled = True
            TxtNguoiDung.Enabled = True
            TxtMatKhau.Enabled = True
        End If
    End Sub
End Class